﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Home_Delete : System.Web.UI.Page
{
    public LanguageManage Language;
    UserEntity currentUser;
    protected void Page_Load(object sender, EventArgs e)
    {
        //Check login
        currentUser = UserManager.Instance.Getuser();
        if (!currentUser.isLogin)
            Response.Redirect("~/Login.aspx");
        Language = new LanguageManage();
        long BookID = 0;
        long categoryID = 0;
        long platformID = 0;
        string userName = "";

        #region DELETE FLOOR, BLOCK, TABLE 

        try
        {
            BookID = long.Parse(Request.QueryString["bookid"]);
            
        }
        catch
        {
        }

        try
        {
            categoryID = long.Parse(Request.QueryString["categoryid"]);
        }
        catch
        {
        }

        try
        {
            platformID = long.Parse(Request.QueryString["platformid"]);
        }
        catch { }

        try
        {
            userName = Request.QueryString["EditUser"].ToString();
        }
        catch { }

        //Delete Item
        if (BookID > 0)
        {
            BookAdapter adp = new BookAdapter();
            bool result = adp.DeleteBook(BookID);
            if (!result)
            {
                //   notify.Text = Language[Utils.ErrorDeleteItem];
                Response.Redirect("Notification.aspx?ErrorDeleteItem=true");
            }
            else
            {
                Response.Redirect("ListBooks.aspx?catelogyid=" + Session["catelogyid"].ToString());
            }
        }

        if (categoryID > 0)
        {
            CategoryAdapter cateAdapter = new CategoryAdapter();
            bool result = cateAdapter.DeleteCategory(categoryID);
            if (!result)
            {
                Response.Redirect("Notification.aspx?ErrorDeleteItem=true");
            }
            else
            {
                Response.Redirect("~/Home/Categories.aspx");
            }
        }

        if (platformID > 0)
        {
            PlatformAdapter platAdapter = new PlatformAdapter();
            bool result = platAdapter.DeletePlatform(platformID);
            if (!result)
            {
                Response.Redirect("Notification.aspx?ErrorDeleteItem=true");
            }
            else
            {
                Response.Redirect("~/Home/Platforms.aspx");
            }
        }

        if (userName!=null)
        {

            UserAdapter userAdapter = new UserAdapter();
            bool result = userAdapter.DeleteUser(userName);
            if (!result)
            {
                Response.Redirect("Notification.aspx?ErrorDeleteItem=true");
            }
            else
            {
                Response.Redirect("~/Home/UserManage.aspx");
            }
        }
        #endregion
    }
}